package com.zhuoding.dao;

import com.zhuoding.domain.Teacher;
import com.zhuoding.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class TeacherDao {
    //JdbcTemplate模板
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());

    //登录功能
    public Teacher login(String username,String password){
        //编写SQL语句
        String sql = "select * from teacher where username = ? and password = ?";
        try{
            //执行SQL语句
            Teacher teacher = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<Teacher>(Teacher.class), username, password);
            //返回结果
            return teacher;
        }catch (Exception e){
            new RuntimeException(e);
        }
       return null;
    }
}
